import { BaselineModel, type Baseline } from "../db/model";

export class BaselineService {
  async getBaseline(userId: string) {
    const baseline = await BaselineModel.findOne({ userId });
    return baseline;
  }

  async createOrUpdateBaseline(userId: string, data: Partial<Baseline>) {
    const baseline = await BaselineModel.findOneAndUpdate(
      { userId },
      { ...data, userId },
      { new: true, upsert: true }
    );
    return baseline;
  }

  async deleteBaseline(userId: string) {
    const result = await BaselineModel.findOneAndDelete({ userId });
    if (!result) {
      throw new Error("基线数据不存在");
    }
    return true;
  }
} 